package main

import (
	"fmt"
	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"study.com/RPCandgRPC/grpc/message"

	//"Gocode/study.com/RPCandgRPC/grpc/message"
	"net"
)


type Person struct {

}
//func (u *Person) GetUser(args models.User, user *string) error {
//	*user = "姓名：" + args.Name + "，" + "年龄："+ strconv.Itoa(args.Age) + "，" + "性别：" + models.Genders[args.Gender]
//	return nil
//}

func (u *Person) GetUser(ctx context.Context, request *message.UserRequest)(*message.User, error) {
	user := message.User{Name: request.Name, Age: request.Age, Gender: message.Gender(request.Gender)}
	return &user, nil
}

func main() {
	//初始化为指针类型
	person := new(Person)
	//将服务器对象注册
	server := grpc.NewServer()
	message.RegisterGetUserServiceServer(server, person)

	//监听
	listen, err := net.Listen("tcp", ":9000")
	if err!=nil{
		fmt.Println("net.Listen error=", err)
		//return
	}
	// 开启服务
	server.Serve(listen)

}


